package PX.希尔排序;

import java.util.Arrays;

public class ShellSort {
    public static void main(String[] args) {
        //测试一把
        int[] arr = new int[]{100,-1,2,1,20,13,12};
        int[] ints = shellsort(arr);
        System.out.println(Arrays.toString(ints));
    }
    public static  int[] shellsort(int[] arr){
        int len = arr.length;
        int temp,grap = len/2;
        while(grap > 0){
            for (int i = 0; i < len; i++) {
                temp = arr[i];
                int preIndex = i - grap;
                while (preIndex >= 0 && arr[preIndex] > temp){
                    arr[preIndex + grap] = arr[preIndex];
                    preIndex -= grap;
                }
                arr[preIndex + grap ] = temp;
            }
            grap /= 2;
        }
        return arr;
    }
}
